package com.zxbit.flash.presenter;

import com.zxbit.flash.BuildConfig;
import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.mvpview.VerifyCodeMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.BlankResponse;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class VerifyCodePresenter extends BasePresenter {
    private VerifyCodeMvpView mvpView;

    public VerifyCodePresenter(VerifyCodeMvpView mvpView) {
        this.mvpView = mvpView;
    }

    public void getVoiceCode(String userName, final int type) {
        Map<String, Object> formMap = new HashMap<String, Object>();
        formMap.put("userName", userName);
        if (type == 1) {
            // 获取短信验证码
            toSubScribe(req.getVerifyCode(BuildConfig.channel, ParamsFactory.getCommonParams(formMap)), new CustomConsumer<BlankResponse>() {
                @Override
                public void call(BlankResponse response) {
                    mvpView.onGetDataNext(response, type);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    mvpView.onGetDataError(throwable);
                }
            });
        } else  {
            // 获取语音验证码
            toSubScribe(req.getVoiceCode(BuildConfig.channel, ParamsFactory.getCommonParams(formMap)), new CustomConsumer<BlankResponse>() {
                @Override
                public void call(BlankResponse response) {
                    mvpView.onGetDataNext(response, type);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    mvpView.onGetDataError(throwable);
                }
            });
        }

    }

}
